using System;
using UnityEngine;

[RequireComponent(typeof(tk2dBaseSprite))]
public class BMThemeSprite : BMThemeBase
{
	public override Color Color
	{
		get
		{
			return this.sprite.color;
		}
		set
		{
			this.sprite.color = value;
		}
	}

	public override ThemeItem[] ThemeItems
	{
		get
		{
			if (this.themeItems == null)
			{
				return null;
			}
			return Array.ConvertAll<ThemeItemSprite, ThemeItem>(this.themeItems, (ThemeItemSprite item) => item);
		}
		set
		{
			if (value == null)
			{
				this.themeItems = null;
			}
			else
			{
				this.themeItems = Array.ConvertAll<ThemeItem, ThemeItemSprite>(value, (ThemeItem item) => item as ThemeItemSprite);
			}
		}
	}

	protected override void Awake()
	{
		base.Awake();
		this.sprite = base.GetComponent<tk2dBaseSprite>();
	}

	public override bool Change(string themeName)
	{
		if (!base.Change(themeName))
		{
			return false;
		}
		ThemeItemSprite themeItemSprite = base.GetThemeItem(themeName) as ThemeItemSprite;
		if (themeItemSprite == null)
		{
			return false;
		}
		if (!this.dontChangeSprite)
		{
			string spriteName = this.sprite.Collection.spriteDefinitions[this.sprite.spriteId].name;
			if (!string.IsNullOrEmpty(themeItemSprite.spriteName))
			{
				spriteName = themeItemSprite.spriteName;
			}
			this.sprite.SetSprite(themeItemSprite.collection, spriteName);
		}
		return true;
	}

	[HideInInspector]
	public bool dontChangeSprite;

	[HideInInspector]
	public ThemeItemSprite[] themeItems;

	private tk2dBaseSprite sprite;
}
